package com.tz.springmvc.framework.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

/**
 * 定义拦截类,实现HandlerInterceptor接口
 * @author Administrator
 *
 */
public class InterceptorTest2 implements HandlerInterceptor {

	//在执行handler方法之前,运行这个方法里面的代码	
	//用户登陆验证
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		System.out.println("InterceptorTest2.preHandler()");
		return true;
	}
	
	//在执行handler方法中,返回ModelAndView之前,运行这个方法里面的代码
	//向页面提供一些公用的数据或者视图信息
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("InterceptorTest2.postHandle()");
		
	}
	
	//执行handler方法之后,运行这个里面的代码
	//比如:统一的异常处理 
	//计算某个handler方法的执行时间:afterCompletion-preHandler
	//统一的日志记录
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("InterceptorTest2.afterCompletion()");
		
	}

	

	

}
